package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.guns.fremework.BaseController;
import cn.stylefeng.guns.fremework.ResponseData;
import cn.stylefeng.guns.modular.system.entity.SysAuditl;
import cn.stylefeng.guns.modular.system.service.SysAuditlService;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
@RequestMapping("/sysAuditl")
public class SysAuditlController extends BaseController {

    private String PREFIX = "/modular/system/sysAuditl";

    @Autowired
    private SysAuditlService sysAuditlService;


    @RequestMapping("")
    public String index() {
        return PREFIX + "/sysAuditl.html";
    }


    @ResponseBody
    @RequestMapping("/page")
    public ResponseData page(Page page, SysAuditl params) {
        LambdaQueryWrapper<SysAuditl> queryWrapper = new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(params.getLogTitle())){
            queryWrapper.and(wrapper -> wrapper.like(SysAuditl::getLogTitle, params.getLogTitle()));
        }
        IPage result = sysAuditlService.page(page, queryWrapper);
        System.out.println("==="+JSON.toJSONString(ResponseData.success(result)));
        return ResponseData.success(result);
    }

    @ResponseBody
    @PostMapping("/update")
    public ResponseData update(SysAuditl params) {
        sysAuditlService.updateById(params);
        return ResponseData.success();
    }

}


